﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TCOChart
{
    public partial class FormLogin : Form
    {
        public FormTableSql form = new FormTableSql();
        bool English = false;

        public FormLogin()
        {
            InitializeComponent();

            select_category.Items.AddRange(new AntdUI.SelectItem[] {
                new AntdUI.SelectItem("one"){
                    Sub = new List<object>{
                        new AntdUI.SelectItem("子菜单1"){
                            Sub=new List<object>{ new AntdUI.SelectItem("sub menu") {
                                Sub=new List<object>{
                                    "one st menu item","two nd menu item","three rd menu item"
                                }
                            } }
                        },
                        new AntdUI.SelectItem( "子菜单2")
                    }
                },
                new AntdUI.SelectItem("two"){ Sub=new List<object>{ "five menu item", "six six six menu item"} },
                new AntdUI.SelectItem("three"),
            });
            select_category.Text = select_category.Items[0].ToString();
        }

        private void button_login_Click(object sender, EventArgs e)
        {
            //if(input_passwd.Text == "123456")
                this.DialogResult = DialogResult.OK;
        }

        private void button_exit_Click(object sender, EventArgs e)
        {
            this.DialogResult=DialogResult.Cancel;  
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!English)
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");

                English = true;
            }
            else
            {
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("");

                English = false;

            }
            ApplyResource();
        }


        private void ApplyResource()
        {
            ComponentResourceManager res = new ComponentResourceManager(typeof(FormLogin));

            // 更新窗体标题
            res.ApplyResources(this, "$this");

            // 更新所有控件
            foreach (Control ctl in Controls)
            {
                res.ApplyResources(ctl, ctl.Name);
                // 递归处理容器控件（如 Panel、GroupBox）
                if (ctl.HasChildren)
                {
                    ApplyResourceToChildControls(ctl, res);
                }
            }
        }

        // 递归更新子控件（适用于嵌套控件）
        private void ApplyResourceToChildControls(Control parent, ComponentResourceManager res)
        {
            foreach (Control ctl in parent.Controls)
            {
                res.ApplyResources(ctl, ctl.Name);
                if (ctl.HasChildren)
                {
                    ApplyResourceToChildControls(ctl, res);
                }
            }
        }
    }
}
